package java041;
import java.util.*;
class PersonSortable implements Comparable<PersonSortable>{
    
    private String name;
    private int age;
    
    public PersonSortable(String name,int age){
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return name +"-"+ age;
    }
    
    @Override
    public int compareTo(PersonSortable o) {
        /*if (this.name.compareTo(o.name)>0) 
            return 1;            
        else if(this.name.compareTo(o.name)<0)           
            return -1;        
        else{
            if (this.age>o.age)             
                return 1;        
            else if(this.age<o.age)
                return -1;
            else
                return 0;
            }        
            */
        int x = this.name.compareTo(o.name);
        if(x!=0){
            return x;
        }
        else{
            if (this.age>o.age)             
                return 1;        
            else if(this.age<o.age)
                return -1;
            else
                return 0;
        }
    }
}

public class Main041 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String name;
        int age;
        PersonSortable [] person = new PersonSortable[n];
        for (int i= 0; i<n ; i++) {
            name = in.next();
            age = in.nextInt();
            person[i] = new PersonSortable(name,age);
        }
        
        Arrays.sort(person);
        for (int j =0 ; j<person.length;j++) {
            System.out.println(person[j]);
        }
        
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));

    }

}
